#
# @lc app=leetcode.cn id=714 lang=python
#
# [714] 买卖股票的最佳时机含手续费
#

# @lc code=start
class Solution(object):
    def maxProfit(self, prices, fee):
        """
        :type prices: List[int]
        :type fee: int
        :rtype: int
        """
        dp = [0]*2
        dp[0] = -prices[0]
        for i in range(1, len(prices)):
            temp = dp[1]
            dp[1] = max(dp[0]+prices[i]-fee, dp[1])
            dp[0] = max(temp-prices[i], dp[0]) 
        return dp[1]
        
# @lc code=end

